package com.weishu.housing.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.weishu.common.core.utils.DateUtils;
import com.weishu.common.core.utils.StringUtils;
import com.weishu.common.core.web.domain.AjaxResult;
import com.weishu.common.security.annotation.PreAuthorize;
import com.weishu.core.entity.*;
import com.weishu.core.service.ICfContractService;
import com.weishu.core.service.ISfContractService;
import com.weishu.core.service.ISfTerminationService;
import com.weishu.core.service.ITbRoomInfoService;
import com.weishu.housing.es.FangyuanEsDto;
import com.weishu.housing.mapper.FangyuanEsMapper;
import com.weishu.housing.service.FangyuanEs;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 房源列表
 */
@RestController
@RequestMapping("/house")
public class RoomInfoController {
    @Resource
    FangyuanEsMapper fangyuanEsMapper;
    @Autowired
    ITbRoomInfoService iTbRoomInfoService;
    @Resource
    private FangyuanEs fangyuanEs;
    /**
     * @author xupeng
     * @param roomInfoEntity
     * @param pageSize
     * @return
     */
    //房源列表
    //rxh修改权限
    @PreAuthorize(hasPermi = "hourse:house:list")
    @RequestMapping("list")
    public AjaxResult s1(RoomInfoEntity roomInfoEntity, Integer pageNo, Integer pageSize) {
        AjaxResult fangyuanquery = fangyuanEs.fangyuanquery(roomInfoEntity, pageNo, pageSize);
        Object data = fangyuanquery.get("data");
        System.out.println(data.toString());
        return fangyuanquery;
    }
//    @PreAuthorize(hasPermi = "hourse:house:esavse")
    @RequestMapping("esavse")
    public AjaxResult esavse() {
        FangyuanEsDto fangyuanEsDto = new FangyuanEsDto();
        List<TbRoomInfo> list = iTbRoomInfoService.list();
        for (TbRoomInfo t:list) {
            System.err.println(t);
            BeanUtils.copyProperties(t,fangyuanEsDto);
            fangyuanEsMapper.save(fangyuanEsDto);
        }
        return AjaxResult.success("添加成功");
    }














}
